package org.spring.springboot.app.set.agenttype.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.springboot.app.set.agenttype.dao.AgentTypeDao;
import org.spring.springboot.app.set.agenttype.domain.po.AgentTypePO;
import org.spring.springboot.app.set.agenttype.domain.vo.AgentTypeVO;
import org.spring.springboot.app.set.agenttype.service.IAgentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AgentTypeServiceImpl implements IAgentTypeService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AgentTypeServiceImpl.class);

    @Autowired
    private AgentTypeDao agentTypeDao;

    @Override
    public List<AgentTypePO> findPage(int pageNum, int pageSize) {
        return agentTypeDao.findPage(pageNum, pageSize);
    }

    @Override
    public AgentTypePO find(String id) {
        return agentTypeDao.selectByPrimaryKey(id);
    }


    @Override
    public int findMaxSort() {
        return agentTypeDao.findMaxSort();
    }

    @Override
    public List<AgentTypePO> selectAllAgentType() {
        return agentTypeDao.selectAllAgentType();
    }

    @Override
    public int save(AgentTypeVO po) {
        po.preInsert();
        return agentTypeDao.insertSelective(po);
    }

    @Override
    public int update(AgentTypePO po) {
        po.preUpdate();
        return agentTypeDao.updateByPrimaryKeySelective(po);
    }

    @Override
    public int delete(String id) {
        AgentTypePO agentTypePO = new AgentTypePO();
        agentTypePO.preDelete();
        agentTypePO.setId(id);
        return agentTypeDao.updateByPrimaryKeySelective(agentTypePO);
    }

    @Override
    public int deletes(String ids) {
        AgentTypePO agentTypePO = new AgentTypePO();
        String[] id_s = ids.split(",");
        agentTypePO.preDelete();
        int count = 0;
        for (String id : id_s) {
            agentTypePO.setId(id);
            count += agentTypeDao.updateByPrimaryKeySelective(agentTypePO);
        }
        return count;
    }
}
